package com.yls.except.util;

import java.util.Map;

/**
 * 经纬度与距离的互换
 * @author xusheng
 * @time 2015-9-9 下午5:32:38   
 * @version 1.0
 * @Description:  {}
 */

public class LngLatRange {
	private static final double EARTH_RADIUS = 6378137;
	private static final double PI = 3.14159265358979323; // 圆周率
	private static final double R = 6371229; // 地球的半径
	
	/**
	 * 两点计算距离
	 * @param longt1
	 * @param lat1
	 * @param longt2
	 * @param lat2
	 * @return
	 */
	public static double getDistance(double longt1, double lat1, double longt2,
			double lat2) {
		double x, y, distance;
		x = (longt2 - longt1) * PI * R
				* Math.cos(((lat1 + lat2) / 2) * PI / 180) / 180;
		y = (lat2 - lat1) * PI * R / 180;
		distance = Math.hypot(x, y);
		return distance;
	}
	
	/**
     * 获取最大最小经纬度
     * @param longitude
     * @param latitude
     * @param distance
	 * @param page 
     * @return
     */
    public static Map<String, Object> MaxMinLngLat(double longitude,
            double latitude, double distance, Map<String, Object> squareMap) {
        // 计算经度弧度,从弧度转换为角度
        double dLongitude = 2 * (Math.asin(Math.sin(distance
                / (2 * EARTH_RADIUS))
                / Math.cos(Math.toRadians(latitude))));
        dLongitude = Math.toDegrees(dLongitude);
        // 计算纬度角度
        double dLatitude = distance / EARTH_RADIUS;
        dLatitude = Math.toDegrees(dLatitude);
        // 正方形
        double left = latitude + dLatitude;
        double right = latitude - dLatitude;
        double up = longitude - dLongitude ;
        double down = longitude + dLongitude;
        squareMap.put("left", left);
        squareMap.put("right", right);
        squareMap.put("up", up);
        squareMap.put("down", down);
        return squareMap;
    }
	public static void main(String[] args) {

	}
	

}
